package com.cmict.data.system.controller.admin.portal;

import com.cmict.data.framework.common.pojo.CommonResult;
import com.cmict.data.framework.common.pojo.PageResult;
import com.cmict.data.system.controller.admin.portal.vo.PortalPageReqVO;
import com.cmict.data.system.controller.admin.portal.vo.PortalRespVO;
import com.cmict.data.system.convert.portal.PortalConvert;
import com.cmict.data.system.dal.dataobject.portal.PortalVersionDO;
import com.cmict.data.system.service.portal.PortalVersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@Api(tags = "历史版本 - 小程序")
@RestController
@RequestMapping("/sys/portal/version")
@Validated
public class PortalVersionController {

    @Resource
    private PortalVersionService portalVersionService;

    @PostMapping("/create")
    @ApiOperation("创建版本")
    public CommonResult<Long> createPortal(@RequestBody PortalVersionDO createReqVO) {
        return CommonResult.success(portalVersionService.createPortal(createReqVO));
    }

    @GetMapping("/page")
    @ApiOperation("获得历史版本分页")
    public CommonResult<PageResult<PortalVersionDO>> getPortalPage(@Valid PortalPageReqVO pageVO) {
        PageResult<PortalVersionDO> pageResult = portalVersionService.getPortalPage(pageVO);
        return CommonResult.success(pageResult);
    }

    @GetMapping("/get")
    @ApiOperation("获得版本")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    public CommonResult<PortalRespVO> getPortal(@RequestParam("id") Long id) {
        PortalVersionDO portal = portalVersionService.getPortal(id);
        return CommonResult.success(PortalConvert.INSTANCE.convertVersion(portal));
    }
}
